/*
 * Copyright (c) Tan Menglong.
 * All rights reserved.
 * 
 * This file is part of the RabbitOS.  The RabbitOS is free software, also known
 * as "open source;" you can redistribute it and/or modify it under the terms
 * of the GNU General Public License (GPL), version 2, as published by the Free
 * Software Foundation (FSF).  To explore alternate licensing terms, contact
 * the Tan Menglong at TanMenglong@gmail.com or +86-15972108715.
 * 
 * The RabbitOS is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GPL for more details.  You should have
 * received a copy of the GPL along with the RabbitOS; see the file COPYING.  If
 * not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
 */
/*
 * Definations of GDT.
 * 03-Mar-08
 */

#ifndef _RABBIT_GDT_H
#define _RABBIT_GDT_H
#include "../sys/types.h"

struct gdt_entry_struct {
	u16int limit_low;
	u16int base_low;
	u8int base_middle;
	u8int access;
	u8int granularity;
	u8int base_high;
} __attribute__ ((packed));

struct gdt_ptr_struct {
	u16int limit;
	u32int base;
} __attribute__ ((packed));

struct idt_entry_struct {
	// The lower 16 bits of the address to jump to when this interrupt fires.
	u16int base_lo;
	// Kernel segment selector.
	u16int sel;
	// This must always be zero.
	u8int always0;
	// More flags. See documentation.
	u8int flags;
	// The upper 16 bits of the address to jump to.
	u16int base_hi;
} __attribute__ ((packed));

struct idt_ptr_struct {
	u16int limit;
	// The address of the first element in our idt_entry_t array.
	u32int base;
} __attribute__ ((packed));

typedef struct gdt_entry_struct gdt_entry_t;
typedef struct gdt_ptr_struct gdt_ptr_t;
typedef struct idt_entry_struct idt_entry_t;
typedef struct idt_ptr_struct idt_ptr_t;

extern void init_gdt(void);
extern void flush_gdt(u32int);
extern void set_gdt_gate(s32int, u32int, u32int, u8int, u8int);
extern void init_idt(void);
extern void gdt_flush(u32int);
#endif							//_RABBIT_GDT_H
